import requests
import re
import time
import random

# 定义要发送请求的URL
url = 'https://www.baidu.com/s'

# 定义请求头
headers = {
    'Host': 'www.baidu.com',
    'Accept': '*/*',
    'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
    'Referer': 'https://www.baidu.com/s',
    'Is_referer': 'https://www.baidu.com/s',
    'Is_xhr': '1',
    'Is_pbs': 'www.baidu.com',
    'Ps-Dataurlconfigqid': '0xdceec6a10001a8b0',
    'X-Requested-With': 'XMLHttpRequest',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'Te': 'trailers',
    'Connection': 'keep-alive'
}

# 定义要发送的请求参数
cookies = {
    'BAIDUID': 'B33CD8DD4700B50CDA4057E78321D558:FG=1',
    'BIDUPSID': 'B33CD8DD4700B50CDA4057E78321D558',
    'PSTM': '1724741754',
    'H_PS_PSSID': '60451_60520_60359_60621_60630_60664_60677_60682_60693',
    'BD_UPN': '13314752',
    'BDORZ': 'B490B5EBF6F3CD402E515D22BCDA1598',
    'COOKIE_SESSION': '168504_0_3_3_5_10_1_2_2_3_3_1_168530_0_18_0_1724910351_0_1724910333%7C3%230_0_1724910333%7C1',
    'H_WISE_SIDS': '60451_60520_60359_60621_60630_60664_60677_60682_60693',
    'BD_HOME': '1',
    'BA_HECTOR': 'ah80a480agal2k010g8ha50hb2oh031jd06p71v',
    'ZFY': 'dZyhVne3ULyBZFWPB95VS0NOkzD8kwCwtt:BigNUd3N4:C',
    'delPer': '0',
    'BD_CK_SAM': '1',
    'PSINO': '7',
    'H_PS_645EC': '1aabvQyXJPaHfnQHQ2IFOQ3Onf%2FPwLBOsr4fBd%2FU7iAY06Xrx4IgvKfgJTI',
    'BDSVRTM': '206',
    'WWW_ST': '1724914481894'
}

# 搜索参数
params = {
    'ie': 'utf-8',
    'mod': '1',
    'isbd': '1',
    'isid': '8453785e006b0b78',
    'f': '3',
    'rsv_bp': '1',
    'rsv_idx': '1',
    'tn': 'baidu',
    'wd': '',  # 这个参数值看起来是乱码，可能需要根据实际情况进行解码或修正
    'fenlei': '256',
    'oq': '',
    'rsv_pq': '8453785e006b0b78',
    'rsv_t': '1aabvQyXJPaHfnQHQ2IFOQ3Onf%2FPwLBOsr4fBd%2FU7iAY06Xrx4IgvKfgJTI',  # 注意URL编码
    'rqlang': 'cn',
    'rsv_enter': '0',
    'rsv_dl': 'ts_1',
    'rsv_btype': 't',
    'rsv_sug3': '2',
    'prefixsug': '',
    'rsp': '1',
    'rsv_sug9': 'es_0_1',
    'rsv_sug4': '688',
    'rsv_sug': '3',
    'bs': '',
    'rsv_sid': '60451_60520_60359_60621_60630_60664_60677_60682_60693',
    '_ss': '1',
    'clist': '54302c96e5eb677f',
    'hsug': '',
    'f4s': '1',
    'csor': '17',
    '_cr1': '41611'
}

# 域名列表   
domain_list = [
    "site:chengxiumingteam.cn",
    "site:360.cn"
]

# 10个不同的User-Agent
user_agents = [
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.59',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 OPR/77.0.4054.203',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Vivaldi/3.8',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Brave/1.25.70',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Whale/2.10.124.26',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Yandex/21.5.0.1209'
]

# 循环遍历域名列表
for domain in domain_list:
    # 替换wd参数为当前域名
    params['wd'] = domain
    params['oq'] = domain  # 如果需要替换oq参数
    params['prefixsug'] = domain  # 如果需要替换prefixsug参数
    params['bs'] = domain

    # 随机选择一个User-Agent
    headers['User-Agent'] = random.choice(user_agents)

    # 发送GET请求
    response = requests.get(url, headers=headers, cookies=cookies, params=params,timeout=10)

    # 设置编码
    response.encoding = 'utf-8'

    # 检查请求是否成功
    if response.status_code == 200:
        # 获取网页内容
        content = response.text

        # 使用正则表达式检查是否包含"百度网址安全中心"
        if re.search(r'百度网址安全中心提醒您', content):
            print(f"网站 {domain}, 可能被入侵挂马")
        else:
            print(f"网站 {domain}, 是安全的。")
    else:
        print(f'请求失败，状态码：{response.status_code}')

    time.sleep(10)  # 每隔10秒检查一次

print("网站挂马检查完毕")